{extend name="_container/table"}



{block name="right"}

<style>
  .header-left{
    width: 0!important;
  }
  .header-right{
    width: 100%!important;
  }
</style>

<div class="layui-inline" >
  <label class="layui-form-label">时间</label>
  <div class="layui-input-inline" style="margin-right: 0px;">
    <input type="text" name="start_time" value="{$Request.param.start_time}" autocomplete="off" class="layui-input" id="test-laydate-start" placeholder="开始日期">
  </div>

  <div class="layui-input-inline">
    <input type="text" name="end_time" value="{$Request.param.end_time}" autocomplete="off" class="layui-input" id="test-laydate-end" placeholder="结束日期">
  </div>
</div>



<div class="layui-inline">
  <label class="layui-form-label">类型</label>
  <div class="layui-input-inline">
    <select name="type" lay-ignore class="select2" style="width: 100px">
      <option value="">请选择</option>
      <option value="1" {$Request.param.type==1?'selected':''}>add</option>
      <option value="2" {$Request.param.type==2?'selected':''}>update</option>
      <option value="3" {$Request.param.type==3?'selected':''}>delete</option>
    </select>
  </div>
</div>

<div class="layui-inline">
  <label class="layui-form-label">表名</label>
  <div class="layui-input-inline">
    <select name="table_name" lay-ignore class="select2" style="width: 200px" id="table_name">
      <option value="">请选择</option>
      {foreach $auto as $v}
      <option value="{$v.name}" {$Request.param.table_name==$v.name?'selected':''}>{$v.name}:{$v.desc}</option>
      {/foreach}
    </select>
  </div>
</div>


<div class="layui-inline">
  <label class="layui-form-label">主键</label>
  <div class="layui-input-inline">
    <input type="text" value="{$Request.param.pk_id}" name="pk_id" class="layui-input" style="width: 60px">
  </div>
</div>

<div class="layui-inline">
  <label class="layui-form-label">字段</label>
  <div class="layui-input-inline">
    <select name="field_name" lay-ignore class="select2" style="width: 200px" id="field_name">
      <option value="">请选择</option>
      {foreach $field as $v}
      <option value="{$v.field_name}" {$Request.param.field_name==$v.field_name?'selected':''}>{$v.field_name}:{$v.field_desc}</option>
      {/foreach}
    </select>
  </div>
</div>


<div class="layui-inline">
  <label class="layui-form-label">用户</label>
  <div class="layui-input-inline">
    <select name="user_id" lay-ignore class="select2" style="width: 150px">
      <option value="">请选择</option>
      {foreach $user_arr as $v}
      <option value="{$v.user_id}" {$Request.param.table_name==$v.user_id?'selected':''}>{$v.username}</option>
      {/foreach}
    </select>
  </div>
</div>


<div class="layui-inline">
  <button type="submit" class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
  </button>
</div>
{/block}

{block name="table_header"}




<th style="width: 100px" >id</th>
<th>表名</th>
<th>表描述</th>
<th>主键</th>
<th>类型</th>
<th>更新字段</th>
<th>用户</th>
<th>时间</th>
<th>查看</th>
{/block}

{block name="table_body"}
<tr>
  
  
  
  
  <td>{$v.id}</td>
  
  
  <td>{$v.table_name}</td>
  <td>{$v.table_auto.desc}</td>
  <td><span class="layui-bg-green layui-badge">{$v.pk_id}</span></td>
  {if $v.type == 'add'}
  <td> <span class="layui-badge layui-bg-gray">{$v.type}</span></td>
  {/if}
  {if $v.type == 'update'}
  <td> <span class="layui-badge layui-bg-orange">{$v.type}</span></td>
  {/if}
  {if $v.type == 'delete'}
  <td> <span class="layui-badge ">{$v.type}</span></td>
  {/if}

  <td>{$v->getData('type') == 2 ? $v['field_name'] : ''}</td>
  <td>{$v.user.username}</td>
  <td>{$v.create_time}</td>

  <td>
    <span href="{:url( 'detail', ['id' => $v.id ]  )}" class="layui-btn layui-btn-sm iframe"    title="详情" data-width="90%" data-height="90%">详情</span>
    {if $v->getData('type') == 2}
    <span href="{:url( 'showData', ['id' => $v.id ]  )}" class="layui-btn layui-btn-danger  layui-btn-sm iframe"    title="详情" data-width="90%" data-height="90%">变化</span>
    {else/}
    <span href="{:url( 'showData', ['id' => $v.id ]  )}" class="layui-btn layui-btn-sm iframe"    title="详情" data-width="90%" data-height="90%">数据</span>
    {/if}
  </td>
</tr>
{/block}



{block name="table_footer"}




{/block}

{block name="js"}
<script>
  layui.use('laydate', function() {
    var laydate = layui.laydate;
    
    
  })
</script>
<script>
  
  $('#table_name').change(
        ()=>{
          let table_name = $('#table_name').val();
          if(table_name){
            $.post(
                    "{:url('getFieldName')}",
                    {table_name},
                    (data)=>{
                      let msg = data.msg;
                      let htmlCode = '<option value="">请选择</option>';
                      for(let i in msg){
                        htmlCode += '<option value="' + msg[i].field_name + '">'   +  msg[i].field_name + ':' + msg[i].field_desc +  '</option>';
                      }
                      $('#field_name').html(htmlCode);
                      $('#field_name').select2();
                    }
            )
          }else{
            $('#field_name').html('<option value="">请选择</option>')
            $('#field_name').select2();
          }
        }
  )
  
  
</script>
{/block}

{/extend}